home *** CD-ROM | disk | FTP | other *** search
/ Aminet 8 / Aminet 8 (1995)(GTI - Schatztruhe)[!][Oct 1995].iso / Aminet / text / hyper / gmake.lha / gmake / c_source / file.c < prev    next >
C/C++ Source or Header  |  1995-08-22  |  4KB  |  195 lines

  1. // file commands
  2. #include "standard.h"
  3. #define feq(a) if(comp_str(type,a))
  4.  
  5. static FILE * gm;        // gmakefile
  6. static BOOL gfile_open=FALSE;
  7. static FILE * gf        // guidefile
  8. static BOOL guide_open=FALSE;
  9. static FILE * cf;        // currentfile
  10. static BOOL current_open=FALSE;
  11.  
  12.  
  13. txt_to_guide(char * msg)
  14.  {
  15.   fprintf(gf,"%s\n",msg)
  16.  }
  17.  
  18. file_to_guide()
  19.  {
  20.   int buffer;
  21.   if(!current_open)
  22.     return;
  23.   REM ("Copying current file to guide");  
  24.   for (buffer = fgetc(cf); buffer !=EOF; buffer = fgetc(cf))
  25.     {
  26.      fputc(buffer,gf)
  27.     }
  28.  }
  29.   
  30.  
  31. BOOL open_file(char * filename)
  32.  {
  33.   NOTE ("Opening File: ",filename);
  34.  
  35.   if((cf = fopen(filename,"r")) == NULL)
  36.         {
  37.     MTEXT error_msg;
  38.     sprintf(error_msg, "Unable to open file: %s", filename);
  39.         perr(error_msg);
  40.         current_open = FALSE;
  41.         }
  42.    else {current_open = TRUE;}
  43.    return current_open;
  44.  }
  45.  
  46. close_file()
  47.  {
  48.    if(!current_open)
  49.     return;
  50.    fclose(cf);
  51.    REM ("Closing current file");
  52.    current_open = FALSE;
  53.  }
  54.  
  55.  
  56.  
  57. BOOL open_gmakefile(char * gmakefile)
  58.  {    
  59.    NOTE ("gmakefile: ",gmakefile);    
  60.  
  61.    if((gm = fopen(gmakefile,"r")) == NULL)
  62.     {
  63.     perr("Unable to open gmakefile.");
  64.     gfile_open = FALSE;
  65.     }
  66.    else {gfile_open = TRUE;}
  67.    return gfile_open;
  68.  }    
  69.  
  70. BOOL open_guidefile()
  71.  {
  72.   MTEXT guidefile;
  73.   strcpy (guidefile,getfilename(GUIDE));
  74.   NOTE ("guidefile: ",guidefile);
  75.  
  76.   if((gf = fopen(guidefile,"w")) == NULL)
  77.         {
  78.         perr("Unable to open guidefile.");
  79.         guide_open = FALSE;
  80.         }
  81.    else {guide_open = TRUE;}
  82.    return guide_open;
  83.  }
  84.  
  85. getdata_gmakefile()
  86.  {
  87.   MTEXT buffer;
  88.   BOOL do_loop=TRUE;
  89.  
  90.     while(do_loop)
  91.         {
  92.         if(fgets(buffer, BUFLEN, gm)==NULL)
  93.      {
  94.         REM("End of GMAKEFILE");
  95.         do_loop = FALSE;
  96.      }
  97.     else
  98.      {
  99.         MTEXT type;    // Which type of file it is
  100.         MTEXT file;    // The name of the file
  101.         MTEXT arg;    // Any extra information
  102.         MTEXT trash;    // S__t
  103.  
  104.         strcpy(trash,"");strcpy(file,"");strcpy(arg,""); // Make null
  105.         sscanf(buffer,"%[^:]%[: \t]%[^\n]", type, trash, file);
  106.  
  107.         // Find out the type of command..
  108.         if(type[0] == ';')
  109.             {
  110.               // Comments
  111.             }
  112.         else feq("Guide")
  113.             {
  114.             add_type(GUIDE,file,"");
  115.             }
  116.         else feq("PreMain")
  117.             {
  118.             add_type(PRE,file,"");
  119.             }
  120.         else feq("PostMain")
  121.             {
  122.             add_type(POST,file,"");
  123.             }
  124.         else feq("PreFace")
  125.                         {
  126.                         add_type(PREFACE,file,"Preface");
  127.                         }
  128.         else feq("Disclaimer")
  129.             {
  130.             add_type(DISC,file,"Distribution Disclaimer");
  131.             }
  132.         else feq("About")
  133.             {
  134.             add_type(ABOUT,file,"About the distribution");
  135.             }
  136.         else feq("Author")
  137.                         {
  138.                         add_type(AUTHOR,file,"About the author");
  139.                         }
  140.         else feq("Install")
  141.                         {
  142.                         add_type(INSTALL,file,"How to install the files");
  143.                         }
  144.         else feq("Usage")
  145.                         {
  146.                         add_type(USAGE,file,"How to use the package");
  147.                         }
  148.         else feq("Bugs")
  149.                         {
  150.                         add_type(BUGS,file,"Bugs in the system");
  151.                         }
  152.         else feq("History")
  153.                         {
  154.                         add_type(HISTORY,file,"History");
  155.                         }
  156.         else feq("Page")
  157.             {
  158.             if(fgets(buffer, BUFLEN, gm)==NULL)
  159.                 {
  160.                 REM ("End of GMAKEFILE with page");
  161.                 do_loop = FALSE;
  162.                 }
  163.             else
  164.                 {
  165.                 sscanf(buffer,"%[ \t]%[^\n]", trash, arg);
  166.                 add_type(PAGE,file,arg);
  167.                 }
  168.             }
  169.         else
  170.             {
  171.             REM("Not a recognised type");
  172.             }
  173.      }
  174.     }
  175.  }
  176.  
  177.  
  178. close_files()
  179.  {
  180.    if (gfile_open)
  181.     fclose(gm);
  182.    if (guide_open)
  183.     fclose(gf);
  184.  }
  185.  
  186.  
  187. init_guidefile()
  188.  {
  189.    REM ("putting the initial information into the guide file.");
  190.    fprintf(gf,"@database %s\n",getfilename(GUIDE));
  191.    fprintf(gf,    "@author The Amiga Guide Compiler\n"
  192.         "@(c) Copyright © 1995 Gary Greenhill\n"
  193.         "@wordwrap\n");
  194.  }
  195.